package cn.yunhe.dao.impl;

import cn.yunhe.dao.IAdminDao;
import cn.yunhe.entity.Admin;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Getter
@Setter
@Repository
public class AdminDao extends HibernateTemplate implements IAdminDao {
    @Autowired
    @Qualifier(value = "sessionFactory")
    private SessionFactory sessionFactory;

    @Override
    public List<Admin> getAll() {
        return find("from Admin");
    }

    @Override
    public void register(Admin admin) {
        save(admin);

    }

    @Override
    public Admin login(String a_name, String a_pwd) {
        return (Admin) find("from Admin where a_name=? and a_pwd=?",a_name,a_pwd).get(0);
    }

    @Override
    public Admin get(int a_id) {
        return get(Admin.class, a_id);
    }
}
